|
1
|
|
|
(function() { |
|
2
|
|
|
"use strict"; |
|
3
|
|
|
|
|
4
|
|
|
window.voteSite = function(snUrl) { |
|
5
|
|
|
// Must not redirect the current page until after the external vote |
|
6
|
|
|
// site URL has been opened in a new tab. Use setTimeout to do this. |
|
7
|
|
|
setTimeout(function() { |
|
8
|
|
|
window.location = snUrl; |
|
9
|
|
|
}, 0); |
|
10
|
|
|
}; |
|
11
|
|
|
|
|
12
|
|
|
function doCalc(type, number, totalDest) { |
|
13
|
|
|
var i = 1, total = 0, df=document.FORM; |
|
14
|
|
|
for(; i<=number; i++) { |
|
15
|
|
|
total += df[type+i].value * 1; |
|
16
|
|
|
} |
|
17
|
|
|
df[totalDest].value = total; |
|
18
|
|
|
}; |
|
19
|
|
|
|
|
20
|
|
|
// Recalculate total number of ports, summing over level |
|
21
|
|
|
window.levelCalc = function(maxPortLevel) { |
|
22
|
|
|
doCalc('port', maxPortLevel, 'total'); |
|
23
|
|
|
}; |
|
24
|
|
|
|
|
25
|
|
|
// Recalculate sum of port race percentages |
|
26
|
|
|
window.raceCalc = function() { |
|
27
|
|
|
doCalc('race', 9, 'racedist'); |
|
28
|
|
|
}; |
|
29
|
|
|
|
|
30
|
|
|
// Set the total number of ports to zero |
|
31
|
|
|
window.setZero = function(maxPortLevel) { |
|
32
|
|
|
var df = document.FORM; |
|
33
|
|
|
for (var i=1; i<=maxPortLevel; i++) { |
|
34
|
|
|
df['port'+i].value = 0; |
|
35
|
|
|
} |
|
36
|
|
|
df.total.value = 0; |
|
37
|
|
|
}; |
|
38
|
|
|
|
|
39
|
|
|
// Set the port race distribution to be equal |
|
40
|
|
|
window.setEven = function() { |
|
41
|
|
|
var i = 2, df=document.FORM; |
|
42
|
|
|
df.race1.value = 12; |
|
43
|
|
|
for(; i<=9; i++) { |
|
44
|
|
|
df['race'+i].value = 11; |
|
45
|
|
|
} |
|
46
|
|
|
df.racedist.value = 100; |
|
47
|
|
|
}; |
|
48
|
|
|
|
|
49
|
|
|
var body, currentlyFlashing=false, flashColour, origColour, intervalFlash, timeoutStopFlash; |
|
50
|
|
|
|
|
51
|
|
|
function stopFlash() { |
|
52
|
|
|
clearInterval(intervalFlash); |
|
53
|
|
|
body.style.backgroundColor = origColour; |
|
|
|
|
|
|
54
|
|
|
currentlyFlashing = false; |
|
55
|
|
|
}; |
|
56
|
|
|
|
|
57
|
|
|
function bgFlash() { |
|
58
|
|
|
var body = document.getElementsByTagName('body')[0]; |
|
59
|
|
|
if(body.style.backgroundColor === origColour) { |
|
60
|
|
|
body.style.backgroundColor = flashColour; |
|
61
|
|
|
} |
|
62
|
|
|
else { |
|
63
|
|
|
body.style.backgroundColor = origColour; |
|
64
|
|
|
} |
|
65
|
|
|
}; |
|
66
|
|
|
|
|
67
|
|
|
window.triggerAttackBlink = function(colour) { |
|
68
|
|
|
if(origColour == null) { |
|
|
|
|
|
|
69
|
|
|
origColour = document.getElementsByTagName('body')[0].style.backgroundColor; |
|
70
|
|
|
} |
|
71
|
|
|
flashColour = '#'+colour; |
|
72
|
|
|
clearTimeout(timeoutStopFlash); |
|
73
|
|
|
if (currentlyFlashing === false) { |
|
74
|
|
|
currentlyFlashing = true; |
|
75
|
|
|
//flash 3 times |
|
76
|
|
|
bgFlash(); |
|
77
|
|
|
intervalFlash = setInterval(bgFlash,500); |
|
78
|
|
|
} |
|
79
|
|
|
timeoutStopFlash = setTimeout(stopFlash,3500); |
|
80
|
|
|
}; |
|
81
|
|
|
})(); |
|
82
|
|
|
|
|
83
|
|
|
// Used by shop_hardware.php |
|
84
|
|
|
function recalcOnKeyUp(transaction, hardwareTypeID, cost) { |
|
85
|
|
|
var form = document.getElementById(transaction + hardwareTypeID); |
|
86
|
|
|
form.total.value = form.amount.value * cost; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// Used by planet_defense.php |
|
90
|
|
|
function showWeaponInfo(select) { |
|
91
|
|
|
var target = $(select).data('target'); |
|
92
|
|
|
var show = $("option:selected", select).data('show'); |
|
93
|
|
|
$(target).children().addClass('hide'); |
|
94
|
|
|
$(show).removeClass('hide'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
// Used by game_join.php |
|
98
|
|
|
function showRaceInfo(select) { |
|
99
|
|
|
var race_id = $("option:selected", select).val(); |
|
100
|
|
|
document.getElementById('race_image').src = "images/race/race" + race_id + ".jpg"; |
|
101
|
|
|
document.getElementById('graphframe').src = "images/race/graph/graph" + race_id + ".gif"; |
|
102
|
|
|
var desc = document.getElementById('race_descr'); |
|
103
|
|
|
$(desc).children().addClass('hide'); |
|
104
|
|
|
$(".race_descr" + race_id, desc).removeClass('hide'); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
// Used by alliance_create.php and alliance_stat.php |
|
108
|
|
|
function togglePassword(select) { |
|
109
|
|
|
var showPassword = $(select).val() === "password"; |
|
110
|
|
|
// We need to both toggle the element display (for the user) and toggle the |
|
111
|
|
|
// disabled property (for the form submission). |
|
112
|
|
|
if (showPassword) { |
|
113
|
|
|
$("#password-display").show(); |
|
114
|
|
|
} else { |
|
115
|
|
|
$("#password-display").hide(); |
|
116
|
|
|
} |
|
117
|
|
|
$("#password-input").prop("disabled", !showPassword); |
|
118
|
|
|
} |
|
119
|
|
|
|